//enemy.js

function Enemy(I) {
  I = I || {};      //constructor
        
  I.active = true;
  I.age = Math.floor(Math.random() * 128);      //age is random?
        
  //Once the background has been created, change the spawn point to random openings in the map.
  I.x = CANVAS_WIDTH / 4 + Math.random() * CANVAS_WIDTH / 2;		//spawn X, currently random
  I.y = 0;															//spawn Y, currently at the top
  I.xVelocity = 1;
  I.yVelocity = 2;
        
  I.width = 32;
  I.height = 32;

  //Enemy inBounds
  I.inBounds = function() {
    return I.x >= 0 && I.x <= CANVAS_WIDTH &&
      I.y >= 0 && I.y <= CANVAS_HEIGHT; 
  };

  //Enemy sprite
  I.sprite = Sprite("shark1");

  //Enemy draw
  I.draw = function() {
    this.sprite.draw(canvas, this.x, this.y);
  };

  //Enemy update
  I.update = function() {
    I.x += I.xVelocity;
    I.y += I.yVelocity;
        
    //Speed increases as enemy ages
    I.xVelocity = 3 * Math.sin(I.age * Math.PI / 64);

    I.age++;
        
    //Enemy exists as long as it is in the bounds of the game
    I.active = I.active && I.inBounds();
  };

  //Enemy explode
  I.explode = function() {
    Sound.play("explosion");
        
    this.active = false;
  };

  return I;     //return Enemy

};    //ENEMY 